package com.weirong.smartvault.backservice.service;

import com.weirong.smartvault.dao.ConfirmLogRepository;
import com.weirong.smartvault.entity.CashboxRealtime;
import com.weirong.smartvault.entity.ConfirmLog;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;

import javax.persistence.criteria.Expression;
import javax.persistence.criteria.Path;
import javax.persistence.criteria.Predicate;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: kfeb4
 * Date: 2017/12/28
 * Time: 16:47
 */
@Service
public class ConfirmLogService {
    @Autowired
    ConfirmLogRepository confirmLogRepository;
    public Page<ConfirmLog> findByBranchIdsAndDateWithPaging(List<Integer> Ids,Date date,Integer page,Integer count){//通过机构的ID和时间并分页查询
        Specification<ConfirmLog> specification = (root, criteriaQuery, criteriaBuilder) -> {
            Path<Integer> banchId = root.get("branchId");
            Path<Date> datePath = root.get("confirmTime");
            return criteriaBuilder.and(banchId.in(Ids),criteriaBuilder.greaterThan(datePath,date));
        };

        Sort sort = new Sort(Sort.Direction.DESC, "id");
        Pageable pageable = new PageRequest(page, count, sort);
        return confirmLogRepository.findAll(specification,pageable);
    }
}
